let mysql = require("mysql");
let connection = mysql.createConnection({ host: "localhost", user: "root", password: "root", port: "3306", database: "user" });
connection.connect();

module.exports = {
    //增
    insert: function (User_name, User_age, User_sex) {
        var createTime = new Date().toLocaleString().replace('/', '-').replace('/', '-');
        let addsql = "INSERT into User (`User_name`,`User_age`,`User_sex`,`createTime`) value ('" + User_name + "','" + User_age + "','" + User_sex + "','" + createTime + "')";
        connection.query(addsql, (err, data) => {
            console.log(err);
            console.log(data);
        })
    },
    //删
    delete: function (User_id) {
        let del = "delete from user where `User_id`='" + User_id + "'";
        connection.query(del, (err, data) => {
            console.log(err);
            console.log(data);
        })
    },
    //改
    update: function (User_name, User_age, User_sex) {
        var updateTime = new Date().toLocaleString().replace('/', '-').replace('/', '-');
        let update = "update `User` set `User_age`='" + User_age + "' ,`User_sex`='" + User_sex + "', `updateTime`='" + updateTime + "' where `User_name`='" + User_name + "'";
        connection.query(update, (err, data) => {
            console.log(err);
            console.log(data);
        })
    },
    //查
    select: function (User_name) {
        let sql = "select * from User where `User_name` = '" + User_name + "'";
        connection.query(sql, (err, data) => {
            console.log(err);
            console.log(data);
        });
    }
}